package handdler

import (
	"github.com/gin-gonic/gin"
	"image-gocv/handdler/dto"
	"image-gocv/handdler/helper"
	"image-gocv/pkg/gocv_utils"
	"image-gocv/pkg/secure"
)

func DiffHash(ctx *gin.Context) {
	req := dto.DiffHashRequest{}
	if err := ctx.ShouldBind(&req); err != nil {
		secure.Panic(err)
	}
	similar, err := gocv_utils.MatchTemplate(req.Smail, req.Large, req.Similar)
	helper.Response(ctx, similar, err)
}

func DiffPoint(ctx *gin.Context) {
	req := dto.DiffHashRequest{}
	if err := ctx.ShouldBind(&req); err != nil {
		secure.Panic(err)
	}
	similar, err := gocv_utils.MatchTemplateToPoint(req.Smail, req.Large, req.Similar)
	helper.Response(ctx, similar, err)
}

func DiffMaxVal(ctx *gin.Context) {
	req := dto.DiffHashRequest{}
	if err := ctx.ShouldBind(&req); err != nil {
		secure.Panic(err)
	}
	similar, err := gocv_utils.GetMatchTemplate(req.Smail, req.Large)
	if err != nil {
		helper.Response(ctx, 0, err)
	} else {
		helper.Response(ctx, similar.MaxVal, err)
	}
}
